package com.itheima.d5_resourse;

import java.io.*;

public class Test3 {
    public static void main(String[] args) {


        //try()
        //try括号里面的资源只能放置资源对象
        //继承AutoCloseable借口
        //自动会自动调用close()方法来调用
        try (
            //需求复制照片
            //创建字节输入流管道与源文件接通
            InputStream is = new FileInputStream("D:\\Java\\JavaEE_learn\\IO_learn\\src\\main\\java\\com\\itheima\\itheima04out.txt");
            //创建字节输出流管道和目标文件接通
            OutputStream os = new FileOutputStream("D:\\Java\\JavaEE_learn\\IO_learn\\src\\main\\java\\com\\itheima\\itheima04outCopy.tx");
            Myconnection con =  new Myconnection();
        ){
            //接收所有的字节输入流
//        byte[] bytes = is.readAllBytes();
            byte[] bytes = new byte[1024];
            int len;
            if((len =is.read(bytes)) != -1){
                os.write(bytes,0,len);
            }

            System.out.println(con);
            System.out.println("复制完成");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    }

